<pre>
<?php
 
 for ($bignum = 0;$bignum<1999; $bignum++) {
  $long = sprintf("%06s",$bignum);
  $smallbit = substr($long,3,3);
  $bigbit = substr($long,0,3);
  $out1 = sub999($smallbit);
  $out2 = sub999($bigbit);
  $out = "";
  if ($out2 != "") {
   $out = $out2." THOUSAND ";
  }
  if ($smallbit*1 < 100 && $out2 <> "" && $smallbit*1 > 0) {
   $out = $out."AND ".$out1;
  } else {
   $out .= $out1;
	 
  }
  echo "$long $out\n";
 }
 
function sub999($num) {
 $set1 = array(' ','ONE','TWO','THREE','FOUR','FIVE','SIX','SEVEN','EIGHT','NINE','TEN','ELEVEN','TWELVE','THIRTEEN','FOURTEEN','FIFTEEN','SIXTEEN','SEVENTEEN','EIGHTEEN','NINETEEN');
 $set2 = array('TWENTY','THIRTY','FORTY','FIFTY','SIXTY','SEVENTY','EIGHTY','NINETY'); 
 $out = "";
 
 if ($num > 99) {
  $hunbit = substr($num,0,1);
	$out = $set1[$hunbit]." HUNDRED";
 }
 $tens = substr($num,1,2)*1;
 if ($tens > 0) {
  if ($num > 99) { $out .= " AND ";}
  if ($tens > 19) {
   $out .= $set2[substr($num,1,1)-2]." ".$set1[substr($num,2,1)];
  } else {
   $out .= $set1[$tens*1] ;
  }
 }
 
 
 return $out;
}
 
?>